/*
 * 
 * all of the api is loaded from the cdn - this can be a static folder
 * even another app engine
 * 
 * the html page comes from our app server code - 
 * 
 * the index.js mvc file can be server also by our app server
 * but it maybe faster to serve this code in the html file
 * 
 * see link below - ajile
 * file:///C:/Users/USER/Downloads/Ajile.1.2.1/Ajile.1.2.1/docs/api/Options.htm#mvc
 * 
 * the apps data will be local however on first boot the data can be ajax requested
 * on loaded using a url path
 * like mytillify.com/starbux/config/file
 * this can replace the config file below
 * 
 
 THIS IS A CHANGE
 
 
 */




Namespace ("com.tilify.api");

//Import    ("com.tilify.api.method");
//imports were here

com.tilify.api.index = new function()
{
   isAppLoaded=false;	
   
   // Begin using this index page module.
   function begin(){
   	//window.onload = initialize;// Initialize the Examples page once loaded.
	window.onunload = end(); // End use of this Examples page module.
	// Add listener to observe any import/include events.
	Ajile.AddImportListener(isPageReady);
	//this will eventually point to our cdn
	path="js_28012012/";
	Import    ("com.tilify.api.accounting",path);
	Import    ("com.tilify.api.sync",path);
	Import    ("com.tilify.api.dataplan",path);
	Import    ("com.tilify.api.db",path);
	Import    ("com.tilify.api.til",path);
	Namespace ("com.tilify.ui");
	Import    ("com.tilify.ui.mdv",path);
	return;
			}
         
   // Ends use of this Examples page module by unloading all resources it
   // created and /or acquired since we began using it.
   function end()
   {
      if(typeof Ajile == "undefined") return;
	  Ajile.Unload("com.tilify.api.accounting");
	  Ajile.Unload("com.tilify.api.sync");
	  Ajile.Unload("com.tilify.api.dataplan");
	  Ajile.Unload("com.tilify.api.db");
	  Ajile.Unload("com.tilify.api.til");
	  Ajile.Unload("com.tilify.ui.mdv");
	
	  Ajile.Unload("com.tilify.api.index");   // Release this module.
   	 return;
   }
   // Initialize the app
  
   function initialize(){
  		com.tilify.api.til.initDevice();
	return;
 
   }

   // ImportListener that triggers the Examples page's initialization once all
   // required modules are ready for use.
   function isPageReady(moduleName)
   {
   	 
   	  if (isAppLoaded==true){return;}	
	  //alert(moduleName);
      if ( 
	  undefined ==  com.tilify.api.accounting ||
	  undefined ==  com.tilify.api.sync ||
	  undefined ==  com.tilify.api.dataplan ||
	  undefined ==  com.tilify.api.til ||
	  undefined ==  com.tilify.api.db ||
	  undefined ==  com.tilify.ui.mdv
	  ) 
	  {
	  	return;
	  }
	  Ajile.RemoveImportListener(isPageReady);
      isPageReady = true;
      isAppLoaded=true;
	  initialize();
	  return;
   }
   
   
   // Begin using this Examples page module! 
   begin();
}